package com.gov.hsams.common.lang;

import lombok.Data;

import java.io.Serializable;

@Data
//作用于类上，是以下注解的集合：
// @ToString @EqualsAndHashCode @Getter @Setter @RequiredArgsConstructor
//给前端json结果的统一封装
public class Result implements Serializable {
    private int code;//200正常
    private String msg;
    private Object data;

    public static Result fail(String msg){
        return fail(400,msg,null);
    }
    public static Result fail(String msg,Object data){
        return fail(400,msg,data);
    }
    public static Result fail(int code,String msg,Object data){
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static Result success(Object data){
        Result r = new Result();
        r.setCode(200);
        r.setMsg("OK");
        r.setData(data);
        return r;
    }
    public static Result success(int code,String msg,Object data){
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
}

